<?php
/*
Plugin Name: Scope
Plugin URI: http://code.google.com/p/umb-scope/
Description: The scope plugin lets you post problems on the blog. 
Version: 1.0
Author: umb-scope team
Author URI: http://code.google.com/p/umb-scope/
License: GPL v2
*/

/**
 * Add a new menu under Manage, visible for all users with template viewing level.
 */

add_action( 'admin_menu', 'scope_add_menu_links' );
function scope_add_menu_links() {
global $wp_version, $_registered_pages;
	$view_level= 2;
	$page = 'edit.php';

add_submenu_page($page, 'Manage Scope', 'Manage Scope',  $view_level, 'scope/manage_scope.php');
add_submenu_page('tools.php', 'Manage Scope', 'Manage Scope',  $view_level, 'scope/manage_scope.php');

	
	$code_pages = array('scope.php','problem_submission.php', 'post.php','get_submission.php', 'manage_scope.php', 'Search_Problems.html', 'search_result.php', 'view_problem.php');
	foreach($code_pages as $code_page) {
		$hookname = get_plugin_page_hookname("scope/$code_page", '' );
		$_registered_pages[$hookname] = true;
	}
	
	 
	
		
}

/**
 * This will scan all the content pages that wordpress outputs for our special code. If the code is found, it will replace the requested survey.
 */
add_shortcode( 'SCOPE-SUBMIT', 'scopesSubmit_shortcode' );
function scopesSubmit_shortcode() {
	$contents = '';
	ob_start();
	include (ABSPATH . 'wp-content/plugins/scope/problem_submission.php');
	$contents = ob_get_contents();
	ob_end_clean();
	return $contents;
}

add_shortcode( 'SCOPE-RETRIEVAL', 'scopesRetrieval_shortcode' );
function scopesRetrieval_shortcode() {
	$contents = '';
	ob_start();
	include (ABSPATH . 'wp-content/plugins/scope/Search_Problems.html');
	$contents = ob_get_contents();
	ob_end_clean();
	return $contents;
}



//added DB -- just one simple table at the moment.
add_action('activate_scope/scope_init.php','scope_activate');
function scope_activate() {
	global $wpdb;	
	// Initial options.
	//add_option('scope_questions_per_page', 1);
	//add_option('scope_insert_csv_header', 1);	
//	$database_version = '1';
	//$installed_db = get_option('scope_db_version');	
	//if($database_version != $installed_db) {
		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
		// Create the table structure
		$sql = "CREATE TABLE {$wpdb->prefix}scope (
		ID int(11) unsigned NOT NULL auto_increment, 
		title varchar(50)  CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'None',
		problem varchar(8000) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, 
		name varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'Prof. Bolker', 
		email varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL default 'None', 
		url varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci, 
		date_created datetime NOT NULL, PRIMARY KEY  (ID));";
		dbDelta($sql);
		//update_option( "scope_db_version", $database_version );
	//}
}
?>